include('shared.lua')
local lulz = false --lulz hack
local nearesthole = nil
local NT = 0

function ENT:Draw()            
	self.Entity:DrawModel()
end

function ENT:Think() --hackhackhackhackhackhackhackhackhackhackhackhackhackhackhack D:
	if self.lol == nil then
		self.Entity:Streams()
		self.lol = true
	end
end

function ENT:Streams()
	local effect = EffectData()
	effect:SetEntity(self.Entity)
	util.Effect("hypermass_pinch",effect)
	local effectA = EffectData()
	effectA:SetMagnitude(1)
	effectA:SetEntity(self.Entity)
	util.Effect("hypermass_ring",effectA)
	local effectB = EffectData()
	effectB:SetMagnitude(0)
	effectB:SetEntity(self.Entity)
	util.Effect("hypermass_ring",effectB)
	local effectC = EffectData()
	effectC:SetMagnitude(1)
	effectC:SetEntity(self.Entity)
	util.Effect("hypermass_jet",effectC)
	local effectD = EffectData()
	effectD:SetMagnitude(0)
	effectD:SetEntity(self.Entity)
	util.Effect("hypermass_jet",effectD)
	local effectE = EffectData()
	effectE:SetEntity(self.Entity)
	util.Effect("hypermass_centerring",effectE)
end

function HMThink()
	if NT > CurTime() then return end
	local nearest_Hole = nil
	local distance = 99999999999999999999
	local HMs = ents.FindByClass("sent_spaceanon_hypermass")
	local ply = LocalPlayer()
	for k,v in pairs(HMs) do
		local vdist = (v:GetPos()-ply:GetPos()):Length()
		if vdist < distance then
			distance = vdist
			nearest_Hole = v
		end
	end
	if nearest_Hole ~= nil then --there is food near!
		nearesthole = nearest_Hole
	end
	NT = CurTime()+2
end
hook.Add("Think", "HMNearestThink", HMThink)

function HMDarkness()
	if nearesthole ~= nil then
		if nearesthole:IsValid() then
			local ply = LocalPlayer()
			ca = math.Round(math.Clamp(-((ply:GetPos():Distance(nearesthole:GetPos()))-300), -255, -1))
			surface.SetDrawColor(0, 0, 0, ca)
			surface.DrawRect( 0, 0, surface.ScreenWidth(), surface.ScreenHeight())
		end
	end
end
hook.Add("HUDPaint", "HMDarkness", HMDarkness)


